// generated 2005/6/29 18:27:49 CST by xihels@163.com
//

#ifndef _MSGPAGE_HH
#  define _MSGPAGE_HH


#if !defined(GLADEMM_DATA)
#define GLADEMM_DATA 
#include <gtkmm/accelgroup.h>

class GlademmData
{  
        
        Glib::RefPtr<Gtk::AccelGroup> accgrp;
public:
        
        GlademmData(Glib::RefPtr<Gtk::AccelGroup> ag) : accgrp(ag)
        {  
        }
        
        Glib::RefPtr<Gtk::AccelGroup>  getAccelGroup()
        {  return accgrp;
        }
};
#endif // GLADEMM_DATA

#include <gtkmm/paned.h>
#include <gtkmm/scrolledwindow.h>
#include "MsgBox.h"
#include "MemberList.h"
#include "binnote.h"
#include "stdint.h"
#include <functional>
#include <string>
#include <map>
using std::map;
using std::string;
using std::unary_function;


class ReceiveIMPacket;
class OutPacket;

class BuddyInfo;
class QQSession;

class MsgPage : public Gtk::HPaned
{  
    public:
	MsgPage(BuddyInfo& _buddyInfo, QQSession& _session);
	~MsgPage();
	bool showNormalIM(const ReceiveIMPacket& packet);
	bool showClusterIM(const ReceiveIMPacket& packet);
	void saveLog(const string & filename);	
	void showLog(int time_msg=0);//default will show all msg received and sent
	void sendMessage();
	void refreshMembers();
	void refreshMembersStatus();
	void beginRefreshMembersStatus();
	void hideMemberList();
	bool showedMemberList() const { return memberListShowed;}
	void insertSmiley(int index) { inputMsgBox->insertSmiley(index); }

	Gtk::Widget* getFocusWidget() { return inputMsgBox;}

	void setTitleLabel(Gtk::Label* label) { titlelabel = label; }
	void setTitleColor(bool hascolor);
	void clear() { msgBox->clear(); }
    private:
	
	
	// 长消息的发送，在这里分割
	struct FragmentsBuf { 
	    // 发送长消息时用这个函数分割为长度合适的包
	    // 存放在sendlist中
	    int split(QQSession& session,
		    const    string& message,
		    uint32_t uid,
		    bool     isClusterMessage);	 
	    
	    auto_ptr<OutPacket> sendlist[255];
	};
	
    private:
	MsgPage(const MsgPage& rhs);		    // 禁止拷贝.
	MsgPage& operator = (const MsgPage& rhs);   // 禁止拷贝.
	
	void showMessage( const string& message,
		const string& sender,
		uint32_t senderid,
		uint32_t time);
	

	//bool on_inputMsgBox_key_press_event(GdkEventKey* ev);
	bool on_memberList_double_click_event(GdkEventButton *ev);
	bool on_inputMsgBox_focus_in_event(GdkEventFocus *ev);

	void on_hide();

    private:
	FragmentsBuf fragmenBuf;
	
	MsgBox * msgBox;
	MsgBox * inputMsgBox;
//	MsgBox * logMsgBox;
	MemberList * memberList;
	Gtk::ScrolledWindow *scrolledwindowMemberList;

	BuddyInfo& buddyInfo;
	QQSession& session;
	Gtk::Label* titlelabel;

	uint32_t messageSender;	    // 最后收到的群消息的发送者
	uint32_t messageSequence;   // 最后收到的消息的序列号
	binnote *chatLog;
	bool hasColor;
	bool memberListShowed;
};
#endif
